package br.com.deployment.manager.search;

import br.com.deployment.daoImpl.CategoryDAOImpl;
import br.com.deployment.daoImpl.IssuesDAOImpl;
import br.com.deployment.daoImpl.OptionsDAOImpl;
import br.com.deployment.daoImpl.QuestionnaireResponseDAOImpl;
import br.com.deployment.daoImpl.ResponseDAOImpl;
import br.com.deployment.entities.Category;
import br.com.deployment.entities.Issues;
import br.com.deployment.entities.Options;
import br.com.deployment.entities.QuestionnaireResponse;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class ManagerEditQuestionnaireResponse {

    @EJB
    CategoryDAOImpl categoryService;
    @EJB
    ResponseDAOImpl responseService;
    @EJB
    IssuesDAOImpl issuesService;
    @EJB
    QuestionnaireResponseDAOImpl qRService;
    @EJB
    OptionsDAOImpl optionsService;
    
    // Atributos Objetos
    private QuestionnaireResponse qResponse;
    private Options options;
    //List Objetos
    private List<Category> categorys;
    private List<Issues> issueses;
    private List<Options> optiones;
    private List<Options> lstOptions;

    //Construtor
    public ManagerEditQuestionnaireResponse() {
        qResponse = new QuestionnaireResponse();
        options   = new Options();

    }

    public void update() {
        System.out.println(options.getTitle());
    }

    //Visualiza o Questionnário escolhido
    public void showQuestionnaireResponse(QuestionnaireResponse q) {
        this.qResponse = q;
        categorys = categoryService.findCategoryQuestionnaire(this.qResponse.getQuestionnaire());
        for (Category c : categorys) {
//            issueses = issuesService.findIssuesType(c);
            c.setIssueses(issueses);
            for (Issues i : c.getIssueses()) {
                optiones = optionsService.findOptionsType(i);
                i.setOptions(optiones);
                for (Options o : i.getOptions()) {
                    System.out.println(o.getTitle());
                }
            }
        }
    }

    public void viewIssues(QuestionnaireResponse q) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            showQuestionnaireResponse(q);
            context.getExternalContext().redirect("editEyreIssues.xhtml");
        } catch (IOException ex) {
            Logger.getLogger(ManagerEditQuestionnaireResponse.class
                    .getName()).log(Level.SEVERE, null, ex);
        }
    }

    public List<Category> getCategorys() {
        return categorys;
    }

    public void setCategorys(List<Category> categorys) {
        this.categorys = categorys;
    }

    public List<Options> getLstOptions() {
        return lstOptions;
    }

    public void setLstOptions(List<Options> lstOptions) {
        this.lstOptions = lstOptions;
    }

    public Options getOptions() {
        return options;
    }

    public void setOptions(Options options) {
        this.options = options;
    }
}
